<template>
  <div class="permission-guide">
    <div class="background-pattern">
      <div class="pattern-dots"></div>
    </div>
    
    <div class="guide-header">
      <h1 class="page-title">权限说明</h1>
      <p class="page-subtitle">为了提供更好的服务，我们需要以下权限</p>
    </div>

    <div class="permissions-list">
      <div class="permission-item" v-for="permission in permissions" :key="permission.id">
        <div class="permission-icon" :class="permission.iconClass">
          <div class="icon-wrapper">
            {{ permission.icon }}
          </div>
        </div>
        <div class="permission-content">
          <h3 class="permission-title">{{ permission.title }}</h3>
          <p class="permission-description">{{ permission.description }}</p>
          <div class="permission-purpose">
            <span class="purpose-label">用途：</span>
            <span class="purpose-text">{{ permission.purpose }}</span>
          </div>
        </div>
        <div class="permission-status" :class="permission.status">
          <div class="status-content">
            <span v-if="permission.status === 'granted'" class="status-icon">✓</span>
            <span v-else-if="permission.status === 'denied'" class="status-icon">✗</span>
            <span v-else class="status-icon">?</span>
            <span class="status-text">
              {{ permission.status === 'granted' ? '已授权' : 
                 permission.status === 'denied' ? '已拒绝' : '待授权' }}
            </span>
          </div>
        </div>
      </div>
    </div>

    <div class="privacy-notice">
      <div class="notice-header">
        <h3>隐私保护承诺</h3>
        <div class="notice-badge">🔒 安全可靠</div>
      </div>
      <div class="notice-content">
        <div class="notice-item" v-for="(item, index) in privacyItems" :key="index">
          <div class="notice-icon">{{ item.icon }}</div>
          <span class="notice-text">{{ item.text }}</span>
        </div>
      </div>
    </div>

    <div class="action-buttons">
      <button class="btn-primary" @click="grantAllPermissions" :disabled="isGranting">
        <span class="btn-icon" v-if="isGranting">⏳</span>
        <span class="btn-icon" v-else>🔐</span>
        <span class="btn-text">{{ isGranting ? '授权中...' : '授权所有权限' }}</span>
      </button>
      <button class="btn-secondary" @click="continueWithoutPermissions">
        <span class="btn-icon">→</span>
        <span class="btn-text">继续使用（部分功能受限）</span>
      </button>
    </div>

    <div class="permission-help">
      <details>
        <summary>
          <span class="help-icon">❓</span>
          <span class="help-text">如何手动授权权限？</span>
        </summary>
        <div class="help-content">
          <p>如果自动授权失败，您可以手动授权：</p>
          <ol>
            <li>打开设备设置</li>
            <li>找到应用权限管理</li>
            <li>选择"智慧医疗助手"</li>
            <li>开启需要的权限</li>
          </ol>
        </div>
      </details>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const isGranting = ref(false)

const permissions = ref([
  {
    id: 'camera',
    icon: '📷',
    iconClass: 'camera',
    title: '相机权限',
    description: '用于人脸识别登录和身份验证',
    purpose: '提供更安全的登录方式，支持刷脸登录功能',
    status: 'pending'
  },
  {
    id: 'location',
    icon: '📍',
    iconClass: 'location',
    title: '位置权限',
    description: '用于查找附近的医院和药店',
    purpose: '为您推荐附近的医疗服务机构',
    status: 'pending'
  },
  {
    id: 'notification',
    icon: '🔔',
    iconClass: 'notification',
    title: '通知权限',
    description: '用于接收预约提醒和健康通知',
    purpose: '及时提醒您预约时间和重要健康信息',
    status: 'pending'
  },
  {
    id: 'storage',
    icon: '💾',
    iconClass: 'storage',
    title: '存储权限',
    description: '用于保存健康报告和医疗记录',
    purpose: '离线查看您的健康档案和医疗记录',
    status: 'pending'
  }
])

const privacyItems = [
  { icon: '🔒', text: '所有数据均经过加密处理' },
  { icon: '👤', text: '严格保护用户隐私信息' },
  { icon: '📋', text: '遵循相关法律法规要求' },
  { icon: '🛡️', text: '不会向第三方泄露用户信息' }
]

const emit = defineEmits(['next', 'back', 'finish'])

const grantAllPermissions = async () => {
  isGranting.value = true
  try {
    // 模拟权限请求
    for (const permission of permissions.value) {
      await new Promise(resolve => setTimeout(resolve, 800))
      permission.status = 'granted'
    }
    
    // 保存权限状态
    localStorage.setItem('permissionsGranted', 'true')
    
    // 跳转到下一步
    setTimeout(() => {
      emit('finish')
    }, 1000)
  } catch (error) {
    console.error('权限授权失败:', error)
  } finally {
    isGranting.value = false
  }
}

const continueWithoutPermissions = () => {
  // 保存用户选择
  localStorage.setItem('permissionsGranted', 'false')
  emit('finish')
}
</script>

<style scoped lang="scss">
.permission-guide {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  padding: 20px;
  color: white;
  position: relative;
  overflow: hidden;
}

.background-pattern {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.1;
}

.pattern-dots {
  width: 100%;
  height: 100%;
  background-image: radial-gradient(circle, white 1px, transparent 1px);
  background-size: 20px 20px;
  animation: float 20s ease-in-out infinite;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

.guide-header {
  text-align: center;
  margin-bottom: 50px;
  position: relative;
  z-index: 1;
}

.page-title {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 12px;
  text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  background: linear-gradient(45deg, #ffffff, #f0f0f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-subtitle {
  font-size: 18px;
  opacity: 0.95;
  margin: 0;
  font-weight: 300;
  letter-spacing: 0.5px;
}

.permissions-list {
  margin-bottom: 50px;
  position: relative;
  z-index: 1;
}

.permission-item {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 20px;
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  
  &:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  }
  
  &:nth-child(1) { animation-delay: 0.1s; }
  &:nth-child(2) { animation-delay: 0.2s; }
  &:nth-child(3) { animation-delay: 0.3s; }
  &:nth-child(4) { animation-delay: 0.4s; }
  
  animation: slideInUp 0.6s ease-out forwards;
  opacity: 0;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.permission-icon {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
  position: relative;
  overflow: hidden;
  
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
  }
  
  &:hover::before {
    transform: translateX(100%);
  }
}

.icon-wrapper {
  font-size: 28px;
  position: relative;
  z-index: 1;
}

.permission-icon.camera {
  background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
}

.permission-icon.location {
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}

.permission-icon.notification {
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
}

.permission-icon.storage {
  background: linear-gradient(135deg, #d299c2 0%, #fef9d7 100%);
}

.permission-content {
  flex: 1;
}

.permission-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 6px 0;
  color: #ffffff;
}

.permission-description {
  font-size: 15px;
  margin: 0 0 8px 0;
  opacity: 0.9;
  line-height: 1.4;
}

.permission-purpose {
  font-size: 13px;
  opacity: 0.8;
  line-height: 1.3;
}

.purpose-label {
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
}

.purpose-text {
  color: rgba(255, 255, 255, 0.8);
}

.permission-status {
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  min-width: 80px;
  text-align: center;
  transition: all 0.3s ease;
}

.status-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.status-icon {
  font-size: 14px;
  font-weight: bold;
}

.status-text {
  font-size: 12px;
}

.permission-status.pending {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.permission-status.granted {
  background: linear-gradient(135deg, #48bb78, #38a169);
  box-shadow: 0 4px 15px rgba(72, 187, 120, 0.3);
  animation: successPulse 0.6s ease-out;
}

@keyframes successPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

.permission-status.denied {
  background: linear-gradient(135deg, #f56565, #e53e3e);
  box-shadow: 0 4px 15px rgba(245, 101, 101, 0.3);
}

.privacy-notice {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 40px;
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  z-index: 1;
}

.notice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.notice-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #ffffff;
}

.notice-badge {
  background: linear-gradient(135deg, #48bb78, #38a169);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(72, 187, 120, 0.3);
}

.notice-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.notice-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  transition: all 0.3s ease;
  
  &:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(4px);
  }
}

.notice-icon {
  font-size: 18px;
  margin-right: 12px;
  width: 24px;
  text-align: center;
}

.notice-text {
  font-size: 14px;
  opacity: 0.9;
  font-weight: 500;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 40px;
  position: relative;
  z-index: 1;
}

.btn-primary, .btn-secondary {
  padding: 18px 32px;
  border: none;
  border-radius: 30px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  color: #667eea;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  
  &:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.25);
    background: linear-gradient(135deg, #ffffff 0%, #e9ecef 100%);
  }
  
  &:active:not(:disabled) {
    transform: translateY(-1px);
  }
  
  &:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
  }
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
  
  &:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  }
}

.btn-icon {
  font-size: 18px;
  transition: transform 0.3s ease;
}

.btn-primary:hover:not(:disabled) .btn-icon,
.btn-secondary:hover .btn-icon {
  transform: scale(1.1);
}

.permission-help {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 20px;
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  z-index: 1;
}

.permission-help summary {
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  
  &:hover {
    opacity: 0.8;
    transform: translateX(4px);
  }
}

.help-icon {
  font-size: 16px;
}

.help-text {
  font-size: 15px;
  color: #ffffff;
}

.help-content {
  font-size: 14px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.9);
}

.help-content ol {
  margin: 12px 0;
  padding-left: 24px;
}

.help-content li {
  margin-bottom: 6px;
  position: relative;
}

.help-content li::marker {
  color: rgba(255, 255, 255, 0.8);
  font-weight: 600;
}

@media (max-width: 768px) {
  .permission-guide {
    padding: 15px;
  }
  
  .page-title {
    font-size: 28px;
  }
  
  .page-subtitle {
    font-size: 16px;
  }
  
  .permission-item {
    flex-direction: column;
    text-align: center;
    padding: 20px;
  }
  
  .permission-icon {
    margin-right: 0;
    margin-bottom: 16px;
  }
  
  .permission-status {
    margin-top: 16px;
  }
  
  .notice-content {
    grid-template-columns: 1fr;
  }
  
  .notice-header {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
  
  .btn-primary, .btn-secondary {
    padding: 16px 28px;
    font-size: 15px;
  }
}

@media (max-width: 480px) {
  .page-title {
    font-size: 24px;
  }
  
  .permission-title {
    font-size: 18px;
  }
  
  .permission-description {
    font-size: 14px;
  }
  
  .notice-item {
    padding: 10px 12px;
  }
  
  .notice-text {
    font-size: 13px;
  }
  
  .help-content {
    font-size: 13px;
  }
}
</style> 